home *** CD-ROM | disk | FTP | other *** search
- On Tue, 4 Jun 1996, Anthony Jacques wrote:
-
- > just a quicky... one of the functions that the DEU source code takes a string,
- > and some parameters in the same way as printf (but with an extra one at the
- > beginning). I want to take these parameters, and combine them into a single
- > string (using sprintf) but I dont have any idea how to do this...
-
- Use vsprintf. That's what it's made for. I include a piece of code from a
- server I've written (it's the logging function, supports things like:
- (the real version doesnt use vsprintf anymore because of the risk of
- buffer overruns, but that's besides the point)
-
- log2( LOG_ERROR, "File: %s not found, line: %d", filename, line );
-
- Here is the code (rehacked for ease of reading):
-
- --------- cut here ------------
- void log2( int level, char *format, ... )
- {
- va_list l;
- char str[ 10240 ];
-
- va_start( l, format );
- if( config.debug_level >= level ) {
- vsprintf( str, format, l );
- save_line_to_file( str, "debug.log" );
- }
- va_end( l );
- }
- ----------- cut here ------------
-
-
- --
- Elias Martenson
- elias@omicron.se
-
-